#include "StdAfx.h"
#include "UIManager.h"
#include "UIManagerImpl.h"
#include "UIFrame.h"
#include "UIHookWindow.h"
#include "UIButton.h"
#include "UICaptionButton.h"
#include "UICheckBox.h"
#include "UIEdit.h"
#include "UICombox.h"
#include "UIGroupBox.h"
#include "UIRadioButton.h"
#include "UIStatic.h"
#include "UIListView.h"
#include "UISlider.h"
#include "UIScrollBar.h"
#include "UITreeView.h"
#include "UITabControl.h"
#include "UIProgress.h"
#include "UISpinControl.h"
CUIManager::CUIManager( void )
{

}


CUIManager::~CUIManager( void )
{

}

CUIManager* CUIManager::Create()
{
    return NULL;
//	return new CUIManagerImpl();
}

CUIWindow* CUIManager::FromeHandle( HWND hWnd )
{
    return CUIManagerImpl::FromeHandle( hWnd );
}

CUIWindow* CUIManager::SkinWnd( HWND hWnd )
{
    return CUIManagerImpl::SkinWnd( hWnd );
}

void CUIManager::UnSkinWnd( HWND hWnd )
{
    CUIManagerImpl::UnSkinWnd( hWnd );
}

void CUIManager::Init()
{
    CUIManagerImpl::Init();
}

void CUIManager::UnInit()
{
    CUIManagerImpl::UnInit();
}

BOOL CUIManager::Skin()
{
    return EnumWindows( EnumWindowsProc, NULL );
}

BOOL CUIManager::EnumWindowsProc( HWND hwnd, LPARAM lParam )
{
    TCHAR sClassName[MAX_PATH] = {0};
    ::GetClassName( hwnd, sClassName, MAX_PATH );

    for ( DWORD i = 0; i < _tcslen( sClassName )*sizeof( TCHAR ); i++ )
    {
        sClassName[i] = toupper( sClassName[i] );
    }

    if ( 0 == _tcscmp( sClassName, _T( "#32770" ) ) )
    {
        CUIFrame* pFrame = NULL;
        pFrame = new CUIFrame( hwnd );
        pFrame->SetFrameCaptionImg( _T( "E:\\Project\\CoolUI\\Debug\\Skins\\FrameCaption.png" ), IMG_VEC, 2 );
        pFrame->SetFrameLeftImg( _T( "E:\\Project\\CoolUI\\Debug\\Skins\\frameLeft.png" ), IMG_HOR, 1 );
        pFrame->SetFrameRightImg( _T( "E:\\Project\\CoolUI\\Debug\\Skins\\frameRight.png" ), IMG_HOR, 1 );
        pFrame->SetFrameBottomImg( _T( "E:\\Project\\CoolUI\\Debug\\Skins\\frameBottom.png" ), IMG_VEC, 2 );
        pFrame->SetCloseBtnImg( _T( "E:\\Project\\CoolUI\\Debug\\Skins\\closebtn.png" ), IMG_VEC, 8 );
        pFrame->SetMaxBtnImg( _T( "E:\\Project\\CoolUI\\Debug\\Skins\\MaximizeGlyph17.png" ), IMG_VEC, 8 );
        pFrame->SetMinBtnImg( _T( "E:\\Project\\CoolUI\\Debug\\Skins\\MinimizeGlyph17.png" ), IMG_VEC, 8 );
        pFrame->SetFrameBkImg( _T( "E:\\Project\\CoolUI\\Debug\\Skins\\bk.png" ) );

        CUIHookWindow::HookWindow( pFrame );
//		pFrame->SetFrameMargin(0,70,0,0);
// 		TCHAR* pImgPath=_T("E:\\Project\\CoolUI\\DLG_Demo\\images\\07xinlang.png");
// 		CUICaptionButton* pCapBtn=new CUICaptionButton(pFrame->GetHwnd(),BTN_XINLANG,pImgPath,IMG_HOR,1);
// 		pCapBtn->SetPosition(5,20);
// 		pFrame->AddCaptionButton(pCapBtn);

        EnumChildWindows( hwnd, EnumChildWindowProc, ( LPARAM )hwnd );
    }

    return TRUE;
}

BOOL CUIManager::EnumChildWindowProc( HWND hWnd, LPARAM lParam )
{
    HWND hParent = ( HWND )lParam;
    TCHAR sClassName[MAX_PATH] = {0};
    ::GetClassName( hWnd, sClassName, MAX_PATH );

    for ( DWORD i = 0; i < _tcslen( sClassName )*sizeof( TCHAR ); i++ )
    {
        sClassName[i] = toupper( sClassName[i] );
    }

    if ( 0 == _tcscmp( sClassName, _T( "BUTTON" ) ) )
    {
        DWORD dwStyle =::GetWindowLong( hWnd, GWL_STYLE );

        if ( BS_GROUPBOX == ( dwStyle & BS_GROUPBOX ) )
        {
            CUIGroupBox* pWnd = new CUIGroupBox( hWnd );
            CUIHookWindow::HookWindow( pWnd );
        }
        else if ( BS_CHECKBOX == ( dwStyle & BS_CHECKBOX ) )
        {
            CUICheckBox* pCheckBox = new CUICheckBox( hWnd );
            pCheckBox->LoadImage( _T( "E:\\Project\\CoolUI\\Debug\\Skins\\CheckBox13.png" ), IMG_VEC, 12 );
            CUIHookWindow::HookWindow( pCheckBox );
        }
        else if ( BS_AUTORADIOBUTTON == ( dwStyle & BS_AUTORADIOBUTTON ) )
        {
            CUIRadioButton* pWnd = new CUIRadioButton( hWnd );
            pWnd->LoadImage( _T( "E:\\Project\\CoolUI\\Debug\\Skins\\RadioButton13.png" ), IMG_VEC, 8 );
            CUIHookWindow::HookWindow( pWnd );
        }
        else
        {
            CUIButton* pBtn = new CUIButton( hWnd );
            pBtn->LoadImage( _T( "E:\\Project\\CoolUI\\Debug\\Skins\\Button.png" ), IMG_VEC, 5 );
            CUIHookWindow::HookWindow( pBtn );
        }
    }
    else if ( 0 == _tcscmp( sClassName, _T( "EDIT" ) ) )
    {
        CUIEdit* pWnd = new CUIEdit( hWnd );
        CUIHookWindow::HookWindow( pWnd );
    }
    else if ( 0 == _tcscmp( sClassName, _T( "COMBOBOX" ) ) )
    {
        CUICombox* pWnd = new CUICombox( hWnd );
        CUIHookWindow::HookWindow( pWnd );
    }
    else if ( 0 == _tcscmp( sClassName, _T( "STATIC" ) ) )
    {
        CUIStatic* pWnd = new CUIStatic( hWnd );
        CUIHookWindow::HookWindow( pWnd );
    }
    else if ( 0 == _tcscmp( sClassName, _T( "SYSLISTVIEW32" ) ) )
    {
        CUIListView* pWnd = new CUIListView( hWnd );
        CUIHookWindow::HookWindow( pWnd );
    }
    else if ( 0 == _tcscmp( sClassName, _T( "MSCTLS_TRACKBAR32" ) ) )
    {
        CUISlider* pWnd = new CUISlider( hWnd );
        CUIHookWindow::HookWindow( pWnd );
    }
    else if ( 0 == _tcscmp( sClassName, _T( "SCROLLBAR" ) ) )
    {
        CUIScrollBar* pWnd = new CUIScrollBar( hWnd );
        CUIHookWindow::HookWindow( pWnd );
    }
    else if ( 0 == _tcscmp( sClassName, _T( "SYSTREEVIEW32" ) ) )
    {
        CUITreeView* pWnd = new CUITreeView( hWnd );
        CUIHookWindow::HookWindow( pWnd );
    }
    else if ( 0 == _tcscmp( sClassName, _T( "SYSTABCONTROL32" ) ) )
    {
        CUITabControl* pWnd = new CUITabControl( hWnd );
        CUIHookWindow::HookWindow( pWnd );
    }
    else if ( 0 == _tcscmp( sClassName, _T( "MSCTLS_PROGRESS32" ) ) )
    {
        CUIProgress* pWnd = new CUIProgress( hWnd );
        CUIHookWindow::HookWindow( pWnd );
    }
    else if ( 0 == _tcscmp( sClassName, _T( "MSCTLS_UPDOWN32" ) ) )
    {
        CUISpinControl* pWnd = new CUISpinControl( hWnd );
        CUIHookWindow::HookWindow( pWnd );
    }

    return TRUE;
}


